home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Frameworks / Grant's CGI Framework 1.0b12 / MyCGIProcess.c < prev    next >
Text File  |  1995-12-09  |  3KB  |  118 lines

  1. /*****
  2.  *
  3.  *    Grant's CGI Shell (Common Grant Interface :-)
  4.  *        http://arpp1.carleton.ca/grant/mac/grantscgi.html
  5.  *
  6.  *    MyCGIProcess.c
  7.  *
  8.  *    Sample application using the cgi interface.
  9.  *
  10.  *    MyCGIProcess is where you will do your application specific processing
  11.  *  of the cgi stuff.
  12.  *
  13.  *    by Grant Neufeld
  14.  *
  15.  *    Copyright ©1995 by Grant Neufeld
  16.  *
  17.  *    http://arpp1.carleton.ca/grant/
  18.  *    gneufeld@ccs.carleton.ca
  19.  *    grant@acm.org
  20.  *
  21.  *    This source may be freely used as long as the copyright notice is kept in the source.
  22.  *    I ask that you let me know of any enhancements (read: bug fixes) to this code.
  23.  *    I would also like copies of (or discounts on) anything you produce using this code, please.
  24.  *
  25.  *****/
  26.  
  27. #include "MyConfiguration.h"
  28. #if kCompileWithCGICode
  29.  
  30. #include <string.h>
  31. #include <Threads.h>
  32.  
  33. #include "compiler_stuff.h"
  34. #include "globals.h"
  35.  
  36. #include "CGI.h"
  37. #include "MemoryUtil.h"
  38.         
  39.  
  40. /***  CUSTOM CGI FUNCTION  ***/
  41.  
  42. /* This function is where the CGI is actually processed.
  43.     You should replace its contents with your own.
  44.     You need to allocate (*theCGIHandle)->responseData using MyNewPtr.
  45.     Put an HTTP header at the beginning of (*theCGIHandle)->responseData.
  46.     Put your data immediately following the last character of the HTTP header.
  47.     (*theCGIHandle)->responseData will be automatically deallocated by the CGI handler.
  48.     You should set (*theCGIHandle)->responseSize to be the size of the responseData,
  49.      including null terminator if you have one.
  50.     
  51.     (this function's prototype is defined in CGI.h) */
  52. void
  53. MyCGIProcess ( CGIHdl theCGIHandle )
  54. {
  55.     (*theCGIHandle)->responseSize = gHTTPHeaderOKSize
  56.         + 141 /* size of my constant string */ + 1 /* null terminator */;
  57.     
  58.     (*theCGIHandle)->responseData = (char *) MyNewPtr ( (*theCGIHandle)->responseSize, nil );
  59.     
  60.     if ( (*theCGIHandle)->responseData != nil )
  61.     {
  62.         HLock ( (Handle)theCGIHandle );
  63.         
  64.         strcpy ( (*theCGIHandle)->responseData, (char *)gHTTPHeaderOK );
  65.         strcpy ( &(((*theCGIHandle)->responseData)[gHTTPHeaderOKSize]),
  66.             "\r<TITLE>Grant's CGI Framework<TITLE>\r<BODY>This framework doesn't do anything. You must add your own code to generate useful results.</BODY>\r" );
  67.         
  68.         HUnlock ( (Handle)theCGIHandle );
  69.     }
  70.     else
  71.     {
  72.         (*theCGIHandle)->responseSize = nil;
  73.     }
  74.     
  75.     /* you should try to make liberal use of yielding to other threads,
  76.         especially in for and while loops */
  77.     #if kCompileWithThreadsOptional
  78.     if ( gHasThreadMgr )
  79.     #endif
  80.     {
  81.         YieldToAnyThread ();
  82.     }
  83.     
  84.     /* set application to quit after finishing the event */
  85. //    gQuit = true;
  86. } /* MyCGIProcess */
  87.  
  88.  
  89. /***  CUSTOM CGI INITIALIZATION  ***/
  90. #pragma segment Startup
  91.  
  92. /* Put any of the initialization you need done, here.
  93.     This function will be called once: in-between the startup
  94.     sequence and the main event loop.
  95.     Return true if the initialization was successful, otherwise false.
  96.     An initialization failure will result in the application quitting. */
  97. Boolean
  98. MyCGIStartup ( void )
  99. {
  100.     return true;
  101. } /* MyCGIStartup */
  102.  
  103.  
  104. /***  CUSTOM CGI CLEAN UP  ***/
  105. #pragma segment Main
  106.  
  107. /* This function is called at quitting time. Put any cleanup you need to do in it. */
  108. Boolean
  109. MyCGIQuit ( Boolean allowUserInteract )
  110. {
  111.     return true;
  112. }/* MyCGIQuit */
  113.  
  114.  
  115. #endif    /* kCompileWithCGICode */
  116.  
  117. /*** EOF ***/
  118.